package com.learning.netease.io.bio;

import lombok.extern.slf4j.Slf4j;

import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * ClassName: BioClient
 * Description: 客户端
 * Date: 2021/1/10 22:33 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Slf4j
public class BioClient {
    private static Charset charset = StandardCharsets.UTF_8;

    public static void main(String[] args) throws Exception {
        try (Socket s = new Socket("localhost", 8080)) {
            OutputStream out = s.getOutputStream();

            Scanner scanner = new Scanner(System.in);
            log.info("请输入：");
            String msg = scanner.nextLine();

            // 阻塞方法，写完成后才会返回
            out.write(msg.getBytes(charset));
            scanner.close();
        }
    }
}
